<template>
  <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="昵称" prop="ownerNickname">
    <el-input type="text" v-model="ruleForm.ownerNickname" autocomplete="off"></el-input>
  </el-form-item>
  <el-form-item label="头像" prop="ownerHeadpic">
    <el-input type="text" v-model="ruleForm.ownerHeadpic" autocomplete="off"></el-input>
  </el-form-item>
  <el-form-item label="真实姓名" prop="ownerName">
    <el-input type="text" v-model="ruleForm.ownerName" autocomplete="off" readonly="readonly"></el-input>
  </el-form-item>
  <el-form-item label="手机号" prop="ownerScore">
    <el-input type="text" v-model="ruleForm.ownerScore" autocomplete="off"></el-input>
  </el-form-item>
  <el-form-item label="区域" prop="ownerRegion">
    <el-input type="text" v-model="ruleForm.ownerRegion" autocomplete="off"></el-input>
  </el-form-item>
  <el-form-item label="送货地址" prop="ownerAddress">
    <el-input type="text" v-model="ruleForm.ownerAddress" autocomplete="off"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
    <el-button @click="resetForm('ruleForm')">返回</el-button>
  </el-form-item>
</el-form>
</template>

<script>
import {updateOwner} from '@/services/PetService.js'
export default {
   created(){
        this.ruleForm = this.$route.params;
    }
    ,

    data() {
     
      var validateUserName = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入姓名'));
        } else {
          callback();
        }
      };
      return {
        ruleForm: {
          ownerId: '',
          ownerNickname: '',
          ownerName: '',
          ownerHeadpic: '',
          ownerAddress:'',
          ownerRegion:'',
          ownerScore:'',
        },
        rules: {
          
          ownerName: [
            { validator: validateUserName, trigger: 'blur' }
          ],
         
        }
      };
    },
    methods: {
       submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            updateOwner(this.ruleForm).then((resp) => {
              console.log(resp.data)
              if(resp){
                this.$router.push({name:"PetOwners"});
              }else{
                alert("服务器正忙，添加失败");
              }
            });
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$router.push({name:"PetOwners"});
      },
    }
  }

</script>

<style>

</style>